# 匿名函数
fun = lambda a, b: a + b
r = fun(1, 2)
print(r)

# 内置函数 map
# def f(x):
#     return x ** 2


s = [1, 2, 3, 4, 5]
re = map(lambda x: x ** 2, s)  # map； 映射，一一对应
print(list(re))

# reduce 累积
# 从_functools库导入reduce
from _functools import reduce

re1 = reduce(lambda x, y: x + y, s)
print(re1)

# filter 过滤
r3 = filter(lambda x: x % 2 == 0, s)
print(list(r3))

a = [1, 2, 3, 40, 5, 0, 6, 0, 5]
# 筛选出非0的数组
r4 = filter(lambda x: x != 0, a)
print(list(r4))

# 转换为 1234050605
r5 = reduce(lambda x, y: str(x) + str(y), a)
print(int(r5))
